package zjc.bookkeeping.api;

import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Base64;

public class APIManager {

    public static byte[] PictureRect(byte[] imgData) {

        // 图像矫正
        String ditc = DocumentImageTrimmingCorrection.Recognition(imgData);
        Log.i("图像矫正", ditc);
        byte[] base64decodedBytes = new byte[0];
        try {
            // string转json 获取image的base64格式
            JSONObject jsonObject = new JSONObject(ditc);
            String img_base64 = jsonObject.getJSONObject("result").getString("image");
            Log.i("3.img_base64", img_base64);

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                // base64转二进制
                base64decodedBytes = Base64.getDecoder().decode(img_base64);
                Log.i("4.base64decodedBytes", String.valueOf(base64decodedBytes));
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return base64decodedBytes;
    }
    public static String ShopTicket( byte[] base64decodedBytes){
        String result = "";
        // 商铺小票识别
        result = StoreReceipt.Recognition(base64decodedBytes);

        Log.i("APIManager",result);
        return result;
    }
    public static String TrainTickets( byte[] base64decodedBytes){
        String result = "";
        // 火车票识别
        result = TrainTickets.Recognition(base64decodedBytes);

        Log.i("APIManager",result);
        return result;
    }
    public static String TaxiInvoice( byte[] base64decodedBytes){
        String result = "";
        // 出租车小票识别
        result = TaxiInvoice.Recognition(base64decodedBytes);

        Log.i("APIManager",result);
        return result;
    }
    public static String RoadToll( byte[] base64decodedBytes){
        String result = "";
        // 过路费小票识别
        result = RoadToll.Recognition(base64decodedBytes);

        Log.i("APIManager",result);
        return result;
    }
    public static String ShippingTicket( byte[] base64decodedBytes){
        String result = "";
        //海关进口货物报关单识别
        result = ShippingTicket.Recognition(base64decodedBytes);

        Log.i("APIManager",result);
        return result;
    }
    public static String PassengerTicket( byte[] base64decodedBytes){
        String result = "";
        // 客运票识别
        result = PassengerTicket.Recognition(base64decodedBytes);

        Log.i("APIManager",result);
        return result;
    }
    public static String PlaneTicket( byte[] base64decodedBytes){
        String result = "";
        // 飞机票识别
        result = PlaneTicket.Recognition(base64decodedBytes);

        Log.i("APIManager",result);
        return result;
    }
}
